package cn.tedu.dao;

import cn.tedu.pojo.User3;
import cn.tedu.util.JDBCUtil;

import java.io.Serializable;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class UserDaoImpl implements UserDao {

    @Override
    public List<User3> findAll() {
       Connection con = null;
       PreparedStatement ps = null;
       ResultSet rs = null;
       List<User3> userList = new ArrayList<>();
        try {
            con = JDBCUtil.getConnection();
            String sql = "select * from user3";
            ps= con.prepareStatement(sql);
            rs= ps.executeQuery();

            while (rs.next()){
                User3 user3 = getUser(rs);
                userList.add(user3);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCUtil.getClose(con,ps,rs);
        }


        return userList;
    }

    @Override
    public List<User3> findAllLikeName(String name) {
        return null;

    }

    @Override
    public User3 findAllUP(String Username, String password) {
        return null;
    }

    @Override
    public User3 findAllId(int id) {
        return null;
    }

    @Override
    public int insert(User3 user3) {
        return 0;
    }

    @Override
    public int delete(int id) {
        return 0;
    }

    @Override
    public int update(User3 user3) {
        return 0;
    }

    private User3 getUser(ResultSet rs) throws SQLException {
        User3 user3 = new User3(
                rs.getInt("id"),
                rs.getString("name"),
                rs.getString("username"),
                rs.getString("password")

        );
        return user3;
    }
}
